﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class Main_Master_Customer_CustomerView : System.Web.UI.Page
{
    Datautility du = new Datautility();
    string strsql = "";
    string LID = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["lid"] != null)
        {
            LID = Request.QueryString["lid"].ToString();
        }
        if (!IsPostBack)
        {

            BindSalePerson();
            BindPriceGroup();

            BindGroupName();
            BindTermCondition();
            BindDDLServices();
            nameBind();
            DeliveryNameBind();
            bindcountry();
            bindstate();
            BindTaxType();
            EnableControl();
            BindTaxGroupSales();
            BindTaxGroupPurchase();
            if (DDLSubClass.SelectedValue != "0")
            {
                DDLSubClass.Enabled = true;
            }
            else
            {
                DDLSubClass.Enabled = false;
            }

            if (DDLMainClass.SelectedValue != "0")
            {
                DDLMainClass.Enabled = true;
            }
            else
            {
                DDLMainClass.Enabled = false;
            }

            BindCustomerDetails();
        }
    }
    protected void EnableControl()
    {
        strsql = "Select * from IVR_SETTINGS";
        DataTable DTEnable = du.getdata(strsql);
        if (DTEnable.Rows.Count > 0)
        {
            if (DTEnable.Rows[0]["TCS"].ToString() == "True")
            {
                chkApplyTCS.Enabled = true;
            }
            else
            {
                chkApplyTCS.Checked = false;
                chkApplyTCS.Enabled = false;
            }
            lblSalesPersonMain.Text = DTEnable.Rows[0]["OTHSALEPERSONCAP"].ToString();
            //lblSalePerson.Text = DTEnable.Rows[0]["OTHSALEPERSONCAP"].ToString();

        }
    }
    private void BindGroupName()
    {
        DataTable dt = du.getdata("USP_ACC_GetLedgerForCustomer");
        if (dt.Rows.Count > 0)
        {
            DDLGroupName.DataSource = dt;
            DDLGroupName.DataTextField = "GNAME";
            DDLGroupName.DataValueField = "GID";
            DDLGroupName.DataBind();
        }
    }
    protected void BindTermCondition()
    {
        strsql = "select TRMID,TRMDESC from ACC_TERMSCONDITIONS Order By TRMDESC ASC";
        DataTable dt = du.getdata(strsql);
        lstTermCondition.DataSource = dt;
        lstTermCondition.DataTextField = "TRMDESC";
        lstTermCondition.DataValueField = "TRMID";
        lstTermCondition.DataBind();
        lstTermCondition.Items.Insert(0, new ListItem("", "0"));
        lstTermCondition.SelectedValue = "0";
    }
    protected void BindDDLServices()
    {
        DDLServices.Items.Add(new ListItem("Debit", "0"));
        DDLServices.Items.Add(new ListItem("Credit", "1"));

    }
    protected void nameBind()
    {

        ddlName.Items.Add(new ListItem("M/s", "0"));
        ddlName.Items.Add(new ListItem("Mr.", "1"));
        ddlName.Items.Add(new ListItem("Mrs.", "2"));
        ddlName.Items.Add(new ListItem("Ms.", "3"));
        ddlName.Items.Add(new ListItem(" ", " "));
        ddlName.SelectedIndex = 4;
    }
    protected void DeliveryNameBind()
    {

        DDLDileveryName.Items.Add(new ListItem("M/s", "0"));
        DDLDileveryName.Items.Add(new ListItem("Mr.", "1"));
        DDLDileveryName.Items.Add(new ListItem("Mrs.", "2"));
        DDLDileveryName.Items.Add(new ListItem("Ms.", "3"));
        DDLDileveryName.Items.Add(new ListItem(" ", " "));
        DDLDileveryName.SelectedIndex = 4;
    }
    protected void bindcountry()
    {
        strsql = "select CountryId,CountryName from Country";
        DataTable dt = du.getdata(strsql);
        ddlCountry.DataSource = dt;
        ddlCountry.DataTextField = "CountryName";
        ddlCountry.DataValueField = "CountryId";
        ddlCountry.DataBind();
        DDLDileveryCountry.DataSource = dt;
        DDLDileveryCountry.DataTextField = "CountryName";
        DDLDileveryCountry.DataValueField = "CountryId";
        DDLDileveryCountry.DataBind();
    }
    protected void bindstate()
    {
        strsql = "select StateId,StateName from MAS_State";
        DataTable DT = du.getdata(strsql);
        ddlState.DataSource = DT;
        ddlState.DataTextField = "StateName";
        ddlState.DataValueField = "StateId";
        ddlState.DataBind();
        ddlState.Items.Insert(0, new ListItem("---Select State---", "0"));
        ddlState.SelectedValue = "0";
        DDLDileveryState.DataSource = DT;
        DDLDileveryState.DataTextField = "StateName";
        DDLDileveryState.DataValueField = "StateId";
        DDLDileveryState.DataBind();
        DDLDileveryState.Items.Insert(0, new ListItem("---Select State---", "0"));
        DDLDileveryState.SelectedValue = "0";
    }
    protected void BindSalePerson()
    {
        strsql = "Select * from ACC_SALESPERSON";
        DataTable DTSale = du.getdata(strsql);
        if (DTSale.Rows.Count > 0)
        {
            //grdSalePerson.DataSource = DTSale;
            //grdSalePerson.DataBind();
            //*************Bind Data to Dropdownlist********//
            ddlSalePerson.DataSource = DTSale;
            ddlSalePerson.DataTextField = "SPRNAME";
            ddlSalePerson.DataValueField = "SPRID";
            ddlSalePerson.DataBind();
            ddlSalePerson.Items.Insert(0, new ListItem("", "0"));
        }

    }
    protected void BindPriceGroup()
    {
        strsql = "Select * from ACC_SALESPRICEGROUP";
        DataTable DTPrice = du.getdata(strsql);
        if (DTPrice.Rows.Count > 0)
        {
            //grdPriceGroup.DataSource = DTPrice;
            //grdPriceGroup.DataBind();
            //*************Bind Data to Dropdownlist********//
            ddlPriceGroup.DataSource = DTPrice;
            ddlPriceGroup.DataTextField = "SPGNAME";
            ddlPriceGroup.DataValueField = "SPGID";
            ddlPriceGroup.DataBind();
            ddlPriceGroup.Items.Insert(0, new ListItem("", "0"));

        }

    }
    protected void BindTaxType()
    {
        strsql = "select * from ACC_TAXTYPE";
        DataTable DT = du.getdata(strsql);
        DDLTaxType.DataSource = DT;
        DDLTaxType.DataTextField = "TAXTYPE";
        DDLTaxType.DataValueField = "TAXTYPEID";
        DDLTaxType.DataBind();
        DDLTaxType.Items.Insert(0, new ListItem("", "0"));
    }
    protected void BindTaxMainClass()
    {
        SqlParameter[] sparam =
                                {
                                    new SqlParameter("@TAXTYPEID",DDLTaxType.SelectedValue)
                                };

        DataTable DT = du.getdatausingprocedure("USP_ACC_GetTaxMainClassNames", sparam);
        if (DT.Rows.Count > 0)
        {
            DDLMainClass.DataSource = DT;
            DDLMainClass.DataTextField = "MAINCLASSNAME";
            DDLMainClass.DataValueField = "MAINCLASSID";
            DDLMainClass.DataBind();
        }
        else
        {
            DDLMainClass.Items.Clear();
            DDLMainClass.Items.Insert(0, new ListItem("", "0"));
            DDLMainClass.Enabled = false;
        }

    }
    protected void BindTaxMainClass(string taxtype)
    {
        SqlParameter[] sparam =
                                {
                                    new SqlParameter("@TAXTYPEID",taxtype.ToString())
                                };

        DataTable DT = du.getdatausingprocedure("USP_ACC_GetTaxMainClassNames", sparam);
        if (DT.Rows.Count > 0)
        {
            DDLMainClass.Enabled = true;
            DDLMainClass.DataSource = DT;
            DDLMainClass.DataTextField = "MAINCLASSNAME";
            DDLMainClass.DataValueField = "MAINCLASSID";
            DDLMainClass.DataBind();
        }
        else
        {
            DDLMainClass.Items.Clear();
            DDLMainClass.Items.Insert(0, new ListItem("", "0"));
            DDLMainClass.Enabled = false;

        }

    }
    protected void BindTaxSubClass()
    {

        SqlParameter[] sparam =
                                {
                                    new SqlParameter("@TAXTYPEID",DDLTaxType.SelectedValue),
                                    new SqlParameter("@MAINCLASSID",DDLMainClass.SelectedValue)
                                     
                                };

        DataTable DT = du.getdatausingprocedure("USP_ACC_GetLedTaxSubClass", sparam);
        if (DT.Rows.Count > 0)
        {
            DDLSubClass.Enabled = true;
            DDLSubClass.DataSource = DT;
            DDLSubClass.DataTextField = "SUBCLASSNAME";
            DDLSubClass.DataValueField = "SUBCLASSID";
            DDLSubClass.DataBind();

        }
        else
        {
            DDLSubClass.Items.Clear();
            DDLSubClass.Items.Insert(0, new ListItem("", "0"));
            DDLSubClass.Enabled = false;
        }
    }
    protected void BindTaxSubClass(string taxtypeid, string Mainclassid)
    {

        SqlParameter[] sparam =
                                {
                                    new SqlParameter("@TAXTYPEID",taxtypeid.ToString()),
                                     new SqlParameter("@MAINCLASSID",Mainclassid.ToString())
                                };

        DataTable DT = du.getdatausingprocedure("USP_ACC_GetLedTaxSubClass", sparam);
        if (DT.Rows.Count > 0)
        {
            DDLSubClass.Enabled = true;
            DDLSubClass.DataSource = DT;
            DDLSubClass.DataTextField = "SUBCLASSNAME";
            DDLSubClass.DataValueField = "SUBCLASSID";
            DDLSubClass.DataBind();
        }
        else
        {
            DDLSubClass.Enabled = false;
        }
    }
    protected void BindTaxGroupPurchase()
    {
        DataTable DTPurchase = du.getdatausingprocedure("USP_ACC_GetPurchaseMainClass");
        ddlPurchase.DataSource = DTPurchase;
        ddlPurchase.DataTextField = "MAINCLASSNAME";
        ddlPurchase.DataValueField = "MAINCLASSID";
        ddlPurchase.DataBind();
        ddlPurchase.Items.Insert(0, new ListItem("", "0"));
    }
    protected void BindTaxGroupSales()
    {
        DataTable DTSales = du.getdatausingprocedure("USP_ACC_GetSalesMainClass");
        ddlSales.DataSource = DTSales;
        ddlSales.DataTextField = "MAINCLASSNAME";
        ddlSales.DataValueField = "MAINCLASSID";
        ddlSales.DataBind();
        ddlSales.Items.Insert(0, new ListItem("", "0"));
    }  
    //
    protected void DDLTaxType_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (Convert.ToInt32(DDLTaxType.SelectedValue) > 0)
        {
            DDLMainClass.Enabled = true;
            BindTaxMainClass();
            DDLSubClass.Items.Clear();
            DDLSubClass.Items.Insert(0, new ListItem("", "0"));
            DDLSubClass.Enabled = false;
        }
        else
        {
            DDLMainClass.Items.Clear();
            DDLMainClass.Items.Insert(0, new ListItem("", "0"));
            DDLMainClass.Enabled = false;
        }
    }
    protected void DDLMainClass_SelectedIndexChanged(object sender, EventArgs e)
    {

        if (Convert.ToInt32(DDLMainClass.SelectedValue) > 0)
        {
            DDLSubClass.Enabled = true;
            BindTaxSubClass();

        }
        else
        {
            DDLSubClass.Items.Clear();
            DDLSubClass.Items.Insert(0, new ListItem("", "0"));
            DDLSubClass.Enabled = false;
        }
    }
    protected bool ValidateLedger1()
    {
        strsql = "Select * from ACC_LEDMAST Where LANAME='" + TxtAlterName.Text + "'  AND LANAME<>'' and lid!=" + LID;
        //lblMsg.Text = strsql;
        DataTable DTAName = du.getdata(strsql);
        if (DTAName.Rows.Count > 0)
        {
            lblMsg.Attributes.Remove("class");
            lblMsg.Attributes.Add("class", "false");
            lblMsg.Text = "duplicate Alternate Ledger Name";
            TxtAlterName.Focus();
            return false;
        }
        else
        {
            return true;
        }
    }
    protected bool ValidateLedger()
    {
        strsql = "Select * from ACC_LEDMAST Where LNAME='" + TxtName.Text + "' and lid!=" + LID;
        //lblMsg.Text = strsql;
        DataTable DTName = du.getdata(strsql);
        if (DTName.Rows.Count > 0)
        {
            lblMsg.Attributes.Remove("class");
            lblMsg.Attributes.Add("class", "false");
            lblMsg.Text = "duplicate Ledger Name";
            TxtName.Focus();
            return false;
        }
        else
        {
            return true;
        }
    }
    protected void ddlPurchase_SelectedIndexChanged(object sender, EventArgs e)
    {
        if ((Convert.ToInt32(ddlPurchase.SelectedValue) == 1) || (Convert.ToInt32(ddlPurchase.SelectedValue) == 2))
        {
            ddlSales.SelectedValue = "3";
        }
        else if (Convert.ToInt32(ddlPurchase.SelectedValue) == 5)
        {
            ddlSales.SelectedValue = "6";
        }
        else
        {
            ddlSales.SelectedValue = "0";
        }
    }
    protected void ddlSales_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (Convert.ToInt32(ddlSales.SelectedValue) == 3)
        {
            ddlPurchase.SelectedValue = "1";
        }
        else if (Convert.ToInt32(ddlSales.SelectedValue) == 6)
        {
            ddlPurchase.SelectedValue = "5";
        }
        else
        {
            ddlPurchase.SelectedValue = "0";
        }
    }
    protected void BindCustomerDetails()
    {
        strsql = "select * from Acc_ledmast where lid =" + LID;
        DataTable dt = du.getdata(strsql);
        TxtName.Text = dt.Rows[0]["LName"].ToString();
        TxtAlterName.Text = dt.Rows[0]["LAName"].ToString();
        string selected_ddlgroup = dt.Rows[0]["PGID"].ToString();
        DDLGroupName.SelectedValue = selected_ddlgroup;

        decimal openbal = Convert.ToDecimal(dt.Rows[0]["ACTOPENING"].ToString());
        if (openbal > 0)
        {
            DDLServices.Items[1].Selected = true;
        }
        else
        {
            DDLServices.Items[0].Selected = true;
        }

        TxtOpeningBal.Text = dt.Rows[0]["ACTOPENING"].ToString();
        TxtClosing.Text = dt.Rows[0]["ACTOPENING"].ToString();

        if (dt.Rows[0]["TAXAPPLY"].ToString() == "True")
        {
            ChkTaxType.Enabled = true;
            ChkTaxType.Checked = true;
        }
        else
        {
            ChkTaxType.Enabled = false;
            ChkTaxType.Checked = false;
        }

        if (dt.Rows[0]["COSTCENTREAPPLY"].ToString() == "True")
        {
            ChkCost.Enabled = true;
            ChkCost.Checked = true;
        }
        else
        {
            ChkCost.Enabled = false;
            ChkCost.Checked = false;
        }

        if (dt.Rows[0]["TDSAPPLY"].ToString() == "True")
        {
            ChkTDS.Enabled = true;
            ChkTDS.Checked = true;
        }
        else
        {
            ChkTDS.Enabled = false;
            ChkTDS.Checked = false;
        }


        if (dt.Rows[0]["STAPPLY"].ToString() == "true")
        {
            ChkService.Enabled = true;
            ChkService.Checked = true;
        }
        else
        {
            ChkService.Enabled = false;
            ChkService.Checked = false;
        }



        string sqlcontact = "select * from ACC_LEDCONTACTDETAILS where LID =" + LID;
        DataTable dtContact = du.getdata(sqlcontact);
        if (dtContact.Rows.Count > 0)
        {
            txtContactPerson.Text = dtContact.Rows[0]["PERSON"].ToString();
            txtContactPosition.Text = dtContact.Rows[0]["POSITION"].ToString();
            txtContactPhone.Text = dtContact.Rows[0]["PHONENUM"].ToString();
            txtContactMobile.Text = dtContact.Rows[0]["MOBILENUM"].ToString();
            txtContactEmail.Text = dtContact.Rows[0]["EMAIL"].ToString();
            txtContactFax.Text = dtContact.Rows[0]["FAXNUM"].ToString();
            txtContactRemarks.Text = dtContact.Rows[0]["REMARKS"].ToString();
        }

        string sqlDelivery = "select * from ACC_LEDDELIVERYADDDETAILS where lid =" + LID;
        DataTable dtDelivery = du.getdata(sqlDelivery);
        if (dtDelivery.Rows.Count > 0)
        {
            string dilevery_selected = dtDelivery.Rows[0]["TITLE"].ToString();
            DDLDileveryName.SelectedItem.Text = dilevery_selected;
            txtDileveryName.Text = dtDelivery.Rows[0]["CONTACTNAME"].ToString();
            txtDileveryAddress1.Text = dtDelivery.Rows[0]["ADD1"].ToString();
            txtDileveryAddress2.Text = dtDelivery.Rows[0]["ADD2"].ToString();
            txtDileveryAddress3.Text = dtDelivery.Rows[0]["ADD3"].ToString();
            txtDileveryAddress4.Text = dtDelivery.Rows[0]["ADD4"].ToString();
            txtDileveryPincode.Text = dtDelivery.Rows[0]["PINCODE"].ToString();

            TxtDileveryPhone.Text = dtDelivery.Rows[0]["Phone"].ToString();
            TxtDileveryFax.Text = dtDelivery.Rows[0]["fax"].ToString();
            TxtDileveryPlace.Text = dtDelivery.Rows[0]["place"].ToString();

            string ddl_stateid = dtDelivery.Rows[0]["STATEID"].ToString();
            DDLDileveryState.SelectedValue = ddl_stateid;
            string ddl_country = dtDelivery.Rows[0]["COUNTRY"].ToString();
            DDLDileveryCountry.SelectedItem.Text = ddl_country;
            txtVat.Text = dtDelivery.Rows[0]["LSTNUM"].ToString();

            txtDeliveryVatDate.Text = dtDelivery.Rows[0]["LSTDATE"].ToString().Replace("01/01/1900 00:00:00", "");
            txtDeliveryInterStateDate.Text = dtDelivery.Rows[0]["CSTDATE"].ToString().Replace("01/01/1900 00:00:00", "");
            txtDeliveryCENVATDate.Text = dtDelivery.Rows[0]["CEPADATE"].ToString().Replace("01/01/1900 00:00:00", "");

            txtDeliveryInterState.Text = dtDelivery.Rows[0]["CSTNUM"].ToString();
            txtDeliveryCENVAT.Text = dtDelivery.Rows[0]["CEPANUM"].ToString();

        }

        string sqladress = "select * from ACC_LEDADDRESS where lid=" + LID;
        DataTable dtadress = du.getdata(sqladress);
        if (dtadress.Rows.Count > 0)
        {
            string title_selected = dtadress.Rows[0]["TITLE"].ToString();
            ddlName.SelectedItem.Text = title_selected;
            txtAddName.Text = dtadress.Rows[0]["LNAME"].ToString();
            txtAddress1.Text = dtadress.Rows[0]["ADDRESS1"].ToString();
            txtAddress2.Text = dtadress.Rows[0]["ADDRESS2"].ToString();
            txtAddress3.Text = dtadress.Rows[0]["ADDRESS3"].ToString();
            txtAddPlace.Text = dtadress.Rows[0]["PLACE"].ToString();

            string ddl_stateid = dtadress.Rows[0]["STATEID"].ToString();
            ddlState.SelectedValue = ddl_stateid;
            string ddl_country = dtadress.Rows[0]["COUNTRY"].ToString();
            ddlCountry.SelectedItem.Text = ddl_country;


            txtPin.Text = dtadress.Rows[0]["PINCODE"].ToString();
            txtWebsite.Text = dtadress.Rows[0]["WEBSITE"].ToString();
            txtEmail.Text = dtadress.Rows[0]["EMAIL"].ToString();
            txtPhone.Text = dtadress.Rows[0]["PHONE"].ToString();
            txtFax.Text = dtadress.Rows[0]["FAX"].ToString();
        }

        string Sqlterm = "select * from ACC_LEDTERMSCONDITIONS where lid =" + LID;
        DataTable dtterm = du.getdata(Sqlterm);
        if (dtterm.Rows.Count > 0)
        {
            string term_selected = dtterm.Rows[0]["TRMID"].ToString();
            lstTermCondition.SelectedValue = term_selected;
        }

        string sqlreg = "select * from ACC_LEDREGDETAILS where lid=" + LID;
        DataTable dtreg = du.getdata(sqlreg);
        if (dtreg.Rows.Count > 0)
        {
            txtRegPAN.Text = dtreg.Rows[0]["PAN"].ToString();
            txtRegPANDate.Text = dtreg.Rows[0]["PANDATE"].ToString().Replace("01/01/1900 00:00:00", "");
            txtRegVAT.Text = dtreg.Rows[0]["VATTIN"].ToString();

            txtRegVATDate.Text = dtreg.Rows[0]["VATTINDATE"].ToString().Replace("01/01/1900 00:00:00", "");
            txtRegInterState.Text = dtreg.Rows[0]["CSTNO"].ToString();

            txtRegInterStateDate.Text = dtreg.Rows[0]["CSTDATE"].ToString().Replace("01/01/1900 00:00:00", "");
            txtRegTaxDeduction.Text = dtreg.Rows[0]["TDSNO"].ToString();
            txtRegTaxDeductionDate.Text = dtreg.Rows[0]["TDSDATE"].ToString().Replace("01/01/1900 00:00:00", "");
            txtRegServicetax.Text = dtreg.Rows[0]["SERTNO"].ToString();
            txtRegServiceTaxDate.Text = dtreg.Rows[0]["SERTNDATE"].ToString().Replace("01/01/1900 00:00:00", "");
            txtRegLuxury.Text = dtreg.Rows[0]["LTNO"].ToString();
            txtRegLuxuryDate.Text = dtreg.Rows[0]["LTNDATE"].ToString().Replace("01/01/1900 00:00:00", "");
            txtRegCVNNET.Text = dtreg.Rows[0]["CEPAN"].ToString();
            txtRegCVNNETDate.Text = dtreg.Rows[0]["CEPANDATE"].ToString().Replace("01/01/1900 00:00:00", "");
            txtRegPanRef.Text = dtreg.Rows[0]["PANREF"].ToString();
        }

        string sqloth = "select * from ACC_LEDOTHERDETAILS where lid =" + LID;
        DataTable dtoth = du.getdata(sqloth);
        if (dtoth.Rows.Count > 0)
        {
            if (dtoth.Rows[0]["TCS"].ToString() == "True")
            {
                chkApplyTCS.Enabled = true;
                chkApplyTCS.Checked = true;
            }
            else
            {
                chkApplyTCS.Enabled = false;
                chkApplyTCS.Checked = false;
            }
            if (dtoth.Rows[0]["ACTIVE"].ToString() == "True")
            {
                CHKAvtive.Enabled = true;
                CHKAvtive.Checked = true;
            }
            else
            {
                CHKAvtive.Enabled = false;
                CHKAvtive.Checked = false;
            }
            txtCreditPeriod.Text = dtoth.Rows[0]["CREDITPERIOD"].ToString();
            txtCreditLimit.Text = dtoth.Rows[0]["CREDITLIMIT"].ToString();
            string purchase_selected = dtoth.Rows[0]["PURTAXMAINCLASSID"].ToString();
            ddlPurchase.SelectedValue = purchase_selected;
            string Sales_selected = dtoth.Rows[0]["SALETAXMAINCLASSID"].ToString();
            ddlSales.SelectedValue = Sales_selected;
            string SalePerson_selected = dtoth.Rows[0]["SPRID"].ToString();
            ddlSalePerson.SelectedValue = SalePerson_selected;
            string PriceGroup_selected = dtoth.Rows[0]["SPGID"].ToString();
            ddlPriceGroup.SelectedValue = PriceGroup_selected;
        }

        string sqltax = "select * from ACC_LEDTAXDETAILS where lid =" + LID;
        DataTable DTTax = du.getdata(sqltax);
        if (DTTax.Rows.Count > 0)
        {
            if (Convert.ToDouble(DTTax.Rows[0]["TAXTYPEID"].ToString()) > 0)
            {

                DDLTaxType.SelectedValue = DTTax.Rows[0]["TAXTYPEID"].ToString();
                BindTaxMainClass(DTTax.Rows[0]["TAXTYPEID"].ToString());
                BindTaxSubClass(DTTax.Rows[0]["TAXTYPEID"].ToString(), DTTax.Rows[0]["MAINCLASSID"].ToString());
            }
            if (Convert.ToDouble(DTTax.Rows[0]["MAINCLASSID"].ToString()) > 0)
            {

                BindTaxMainClass(DTTax.Rows[0]["TAXTYPEID"].ToString());
                DDLMainClass.SelectedValue = DTTax.Rows[0]["MAINCLASSID"].ToString();
            }
            if (Convert.ToDouble(DTTax.Rows[0]["SUBCLASSID"].ToString()) > 0)
            {
                BindTaxSubClass(DTTax.Rows[0]["TAXTYPEID"].ToString(), DTTax.Rows[0]["MAINCLASSID"].ToString());
                DDLSubClass.SelectedValue = DTTax.Rows[0]["SUBCLASSID"].ToString();
            }



        }
        else
        {
            DDLTaxType.SelectedValue = "0";
            DDLMainClass.SelectedValue = "0";
            DDLSubClass.SelectedValue = "0";
        }
    }
    protected void UpdateTaxDetails()
    {
      
        if (Convert.ToInt32(DDLTaxType.SelectedValue) > 0)
        {
            try
            {
                
                string sql1 = "select * from ACC_LEDTAXDETAILS where lid=" + LID;
                DataTable DT = du.getdata(sql1);
                if (DT.Rows.Count > 0)
                {

                    SqlParameter[] sparam = 
                                        { 
                                            new SqlParameter("@TAXTYPEID",DDLTaxType.SelectedValue),
                                            new SqlParameter("@MAINCLASSID",DDLMainClass.SelectedValue),
                                            new SqlParameter("@SUBCLASSID",DDLSubClass.SelectedValue),
                                            new SqlParameter("@TAXDETAILID",LID) ,
                                            new SqlParameter("EName",Session["username"].ToString())
                                        };

                    du.executeprocedure("USP_ACC_SaveLedgerTaxDetails", sparam);
                }

                else
                {

                    SqlParameter[] sparam = 
                                        { 
                                            new SqlParameter("@LID",LID),
                                            new SqlParameter("@TAXTYPEID",DDLTaxType.SelectedValue),
                                            new SqlParameter("@MAINCLASSID",DDLMainClass.SelectedValue),
                                            new SqlParameter("@SUBCLASSID",DDLSubClass.SelectedValue),
                                            new SqlParameter("@TAXDETAILID",LID) ,
                                             new SqlParameter("CName",Session["username"].ToString())
                                            
                                        };
                    
                    du.executeprocedure("USP_ACC_SaveLedgerTaxDetails", sparam);

                }
            }


            catch (Exception ex)
            {
                lblMsg.Text = ex.Message;
            }
        }
    }    
    protected void UpdateWithGroup()
    {
        try
        {
            SqlParameter[] param = {
                                       new SqlParameter("@LID",LID),
                                      new SqlParameter("@PGID",DDLGroupName.SelectedValue),
                                      new SqlParameter("@LNAME",TxtName.Text.Trim()),
                                      new SqlParameter("@LANAME",TxtAlterName.Text.Trim()),
                                      new SqlParameter("@ACTOPENING", TxtOpeningBal.Text.Trim()),
                                      new SqlParameter("@BILLWISE","0"),
                                      new SqlParameter("@ALWSUB","0"),                                  
                                      new SqlParameter("@TAXAPPLY",ChkTaxType.Checked),
                                      new SqlParameter("@COSTCENTREAPPLY",ChkCost.Checked),
                                      new SqlParameter("@TDSAPPLY",ChkTDS.Checked),
                                      new SqlParameter("@STAPPLY",ChkService.Checked),                                 
                                      new SqlParameter("EName",Session["username"].ToString()),
                                      new SqlParameter("@VCODE","0")
                                  };
            du.executeprocedure("usp_update_ACC_LEDMAST", param);
        }
        catch (Exception ex)
        {
            lblMsg.Attributes.Remove("class");
            lblMsg.Attributes.Add("class", "false");
            lblMsg.Text = ex.Message;
        }
    }
    protected void UpdateAddressDetails()
    {
        try
        {
            string sql1 = "select * from ACC_LEDADDRESS where lid=" + LID;
            DataTable DT = du.getdata(sql1);
            if (DT.Rows.Count > 0)
            {
                SqlParameter[] sparam1 = 
                            { 
                                new SqlParameter("@LID",LID),
                                new SqlParameter("@TITLE",ddlName.SelectedItem.Text.Trim()),
                                new SqlParameter("@LNAME",txtAddName.Text.Trim()),
                                new SqlParameter("@ADDRESS1",txtAddress1.Text.Trim()),
                                new SqlParameter("@ADDRESS2",txtAddress2.Text.Trim()),
                                new SqlParameter("@ADDRESS3",txtAddress3.Text.Trim()),
                                new SqlParameter("@PLACE",txtAddPlace.Text.Trim()),
                                new SqlParameter("@PINCODE",txtPin.Text.Trim()),
                                new SqlParameter("@STATEID",ddlState.SelectedValue),
                                new SqlParameter("@COUNTRY",ddlCountry.SelectedItem.Text),
                                new SqlParameter("@WEBSITE",txtWebsite.Text.Trim()),
                                new SqlParameter("@EMAIL",txtEmail.Text.Trim()),
                                new SqlParameter("@PHONE",txtPhone.Text.Trim()),
                                new SqlParameter("@FAX",txtFax.Text.Trim()),
                                new SqlParameter("@EName",Session["username"].ToString()),
                            };

                du.executeprocedure("usp_update_ACC_LedgerAddressDetails", sparam1);
            }
            else
            {
                SqlParameter[] sparam = 
                            { 
                                new SqlParameter("@LID",LID),
                                new SqlParameter("@TITLE",ddlName.SelectedItem.Text.Trim()),
                                new SqlParameter("@LNAME",txtAddName.Text.Trim()),
                                new SqlParameter("@ADDRESS1",txtAddress1.Text.Trim()),
                                new SqlParameter("@ADDRESS2",txtAddress2.Text.Trim()),
                                new SqlParameter("@ADDRESS3",txtAddress3.Text.Trim()),
                                new SqlParameter("@PLACE",txtAddPlace.Text.Trim()),
                                new SqlParameter("@PINCODE",txtPin.Text.Trim()),
                                new SqlParameter("@STATEID",ddlState.SelectedValue),
                                new SqlParameter("@COUNTRY",ddlCountry.SelectedItem.Text),
                                new SqlParameter("@WEBSITE",txtWebsite.Text.Trim()),
                                new SqlParameter("@EMAIL",txtEmail.Text.Trim()),
                                new SqlParameter("@PHONE",txtPhone.Text.Trim()),
                                new SqlParameter("@FAX",txtFax.Text.Trim()),
                                new SqlParameter("@CNAME",Session["username"].ToString())
                            };
                du.executeprocedure("USP_ACC_SaveLedgerAddressDetails", sparam);
            }
        }
        catch (Exception ex)
        {
            lblMsg.Attributes.Remove("class");
            lblMsg.Attributes.Add("class", "false");
            lblMsg.Text = ex.Message;
        }
    }
    protected void UpdatetContactDetails()
    {
        try
        {

            string sql1 = "select * from ACC_LEDCONTACTDETAILS where lid=" + LID;
            DataTable DT = du.getdata(sql1);
            if (DT.Rows.Count > 0)
            {
                SqlParameter[] sparam = 
                                        { 
                                            new SqlParameter("@LID",LID),
                                            new SqlParameter("@PERSON",txtContactPerson.Text.Trim()),
                                            new SqlParameter("@POSITION",txtContactPosition.Text.Trim()),
                                            new SqlParameter("@PHONENUM",txtContactPhone.Text.Trim()),
                                            new SqlParameter("@MOBILENUM",txtContactMobile.Text.Trim()),
                                            new SqlParameter("@EMAIL",txtContactEmail.Text.Trim()),
                                            new SqlParameter("@FAXNUM",txtContactFax.Text.Trim()),
                                            new SqlParameter("@REMARKS",txtContactRemarks.Text.Trim()),
                                            new SqlParameter("@ENAME",Session["username"].ToString())
                                            
                                        };
                du.executeprocedure("usp_update_ACC_LedgerContactDetails", sparam);

            }
            else
            {
                // lblMsg.Text= "update";
                SqlParameter[] sparam = 
                                        { 
                                            new SqlParameter("@LID",LID),
                                            new SqlParameter("@PERSON",txtContactPerson.Text.Trim()),
                                            new SqlParameter("@POSITION",txtContactPosition.Text.Trim()),
                                            new SqlParameter("@PHONENUM",txtContactPhone.Text.Trim()),
                                            new SqlParameter("@MOBILENUM",txtContactMobile.Text.Trim()),
                                            new SqlParameter("@EMAIL",txtContactEmail.Text.Trim()),
                                            new SqlParameter("@FAXNUM",txtContactFax.Text.Trim()),
                                            new SqlParameter("@REMARKS",txtContactRemarks.Text.Trim()),
                                            new SqlParameter("@CNAME",Session["username"].ToString())
                                            
                                        };

                du.executeprocedure("USP_ACC_SaveLedgerContactDetails", sparam);
            }
        }
        catch (Exception ex)
        {
            lblMsg.Attributes.Remove("class");
            lblMsg.Attributes.Add("class", "false");
            lblMsg.Text = ex.Message;
        }
    }
    protected void UpdateDeliveryDetails()
    {

        try
        {

            string sql1 = "select * from ACC_LEDDELIVERYADDDETAILS where lid=" + LID;
            DataTable DT = du.getdata(sql1);
            if (DT.Rows.Count > 0)
            {
                string LstDate = "";
                string CSTDate = "";
                string CepDate = "";



                if (txtDeliveryVatDate.Text != "")
                {
                    string[] Lst = txtDeliveryVatDate.Text.Split(new char[] { '/' });
                    LstDate = Lst[1].ToString() + "/" + Lst[0].ToString() + "/" + Lst[2].ToString();
                }

                if (txtDeliveryInterStateDate.Text != "")
                {
                    string[] CST = txtDeliveryInterStateDate.Text.Split(new char[] { '/' });
                    CSTDate = CST[1].ToString() + "/" + CST[0].ToString() + "/" + CST[2].ToString();
                }
                if (txtDeliveryCENVATDate.Text != "")
                {
                    string[] Cep = txtDeliveryCENVATDate.Text.Split(new char[] { '/' });
                    CepDate = Cep[1].ToString() + "/" + Cep[0].ToString() + "/" + Cep[2].ToString();
                }

                SqlParameter[] sparam = 
                                        {
                                            new SqlParameter("@LID",LID),
                                            new SqlParameter("@TITLE",DDLDileveryName.SelectedItem.Text.Trim()),
                                            new SqlParameter("@CONTACTNAME",txtDileveryName.Text.Trim()),
                                            new SqlParameter("@ADD1",txtDileveryAddress1.Text.Trim()),
                                            new SqlParameter("@ADD2",txtDileveryAddress2.Text.Trim()),
                                            new SqlParameter("@ADD3",txtDileveryAddress3.Text.Trim()),
                                            new SqlParameter("@ADD4",txtDileveryAddress4.Text.Trim()),
                                            new SqlParameter("@PINCODE",txtDileveryPincode.Text.Trim()),
											new SqlParameter("@place", TxtDileveryPlace.Text.Trim()),
                                            new SqlParameter("@fax", TxtDileveryFax.Text.Trim()),
                                            new SqlParameter("@phone", TxtDileveryPhone.Text.Trim()),new SqlParameter("@STATEID",DDLDileveryState.SelectedValue),
                                            new SqlParameter("@COUNTRY",DDLDileveryCountry.SelectedItem.Text.Trim()),
                                            new SqlParameter("@LSTNUM",txtVat.Text.Trim()),
                                            new SqlParameter("@LSTDATE",LstDate),
                                            new SqlParameter("@CSTNUM",txtDeliveryInterState.Text.Trim()),
                                            new SqlParameter("@CSTDATE",CSTDate),
                                            new SqlParameter("@CEPANUM",txtDeliveryCENVAT.Text.Trim()),
                                            new SqlParameter("@CEPADATE",CepDate),
                                            new SqlParameter("@ENAME",Session["username"].ToString())
                                        };
                du.executeprocedure("usp_update_ACC_LedgerDeliveryAddressDetails", sparam);


            }
            else
            {

                string LstDate = "";
                string CSTDate = "";
                string CepDate = "";



                if (txtDeliveryVatDate.Text != "")
                {
                    string[] Lst = txtDeliveryVatDate.Text.Split(new char[] { '/' });
                    LstDate = Lst[1].ToString() + "/" + Lst[0].ToString() + "/" + Lst[2].ToString();
                }

                if (txtDeliveryInterStateDate.Text != "")
                {
                    string[] CST = txtDeliveryInterStateDate.Text.Split(new char[] { '/' });
                    CSTDate = CST[1].ToString() + "/" + CST[0].ToString() + "/" + CST[2].ToString();
                }
                if (txtDeliveryCENVATDate.Text != "")
                {
                    string[] Cep = txtDeliveryCENVATDate.Text.Split(new char[] { '/' });
                    CepDate = Cep[1].ToString() + "/" + Cep[0].ToString() + "/" + Cep[2].ToString();
                }

                SqlParameter[] sparam = 
                                        {
                                            new SqlParameter("@LID",LID),
                                            new SqlParameter("@TITLE",DDLDileveryName.SelectedItem.Text.Trim()),
                                            new SqlParameter("@CONTACTNAME",txtDileveryName.Text.Trim()),
                                            new SqlParameter("@ADD1",txtDileveryAddress1.Text.Trim()),
                                            new SqlParameter("@ADD2",txtDileveryAddress2.Text.Trim()),
                                            new SqlParameter("@ADD3",txtDileveryAddress3.Text.Trim()),
                                            new SqlParameter("@ADD4",txtDileveryAddress4.Text.Trim()),
                                            new SqlParameter("@PINCODE",txtDileveryPincode.Text.Trim()),
                                            new SqlParameter("@STATEID",DDLDileveryState.SelectedValue),
                                            new SqlParameter("@COUNTRY",DDLDileveryCountry.SelectedItem.Text.Trim()),
											new SqlParameter("@place", TxtDileveryPlace.Text.Trim()),
                                            new SqlParameter("@fax", TxtDileveryFax.Text.Trim()),
                                            new SqlParameter("@phone", TxtDileveryPhone.Text.Trim()),
                                            new SqlParameter("@LSTNUM",txtVat.Text.Trim()),
                                            new SqlParameter("@LSTDATE",LstDate),
                                            new SqlParameter("@CSTNUM",txtDeliveryInterState.Text.Trim()),
                                            new SqlParameter("@CSTDATE",CSTDate),
                                            new SqlParameter("@CEPANUM",txtDeliveryCENVAT.Text.Trim()),
                                            new SqlParameter("@CEPADATE",CepDate),
                                            new SqlParameter("@CNAME",Session["username"].ToString())
                                        };
                du.executeprocedure("USP_ACC_SaveLedgerDeliveryAddressDetails", sparam);
            }
        }
        catch (Exception ex)
        {
            lblMsg.Text = ex.Message;
            lblMsg.Attributes.Remove("class");
            lblMsg.Attributes.Add("class", "false");
        }
    }
    protected void UpdateRegistrationDetails()
    {
        try
        {
            string sql1 = "select * from ACC_LEDREGDETAILS where lid=" + LID;
            DataTable DT = du.getdata(sql1);
            if (DT.Rows.Count > 0)
            {
                string PANDate = "";
                string VatDate = "";
                string CSTDate = "";
                string TDSDate = "";
                string STDate = "";
                string LTDate = "";
                string CENVATDate = "";
                if (txtRegPANDate.Text != "")
                {
                    string[] Pan = txtRegPANDate.Text.Split(new char[] { '/' });
                    PANDate = Pan[1].ToString() + "/" + Pan[0].ToString() + "/" + Pan[2].ToString();
                }
                if (txtRegVATDate.Text != "")
                {
                    string[] DedcutionTax = txtRegVATDate.Text.Split(new char[] { '/' });
                    VatDate = DedcutionTax[1].ToString() + "/" + DedcutionTax[0].ToString() + "/" + DedcutionTax[2].ToString();
                }
                if (txtRegInterStateDate.Text != "")
                {
                    string[] RegInterState = txtRegInterStateDate.Text.Split(new char[] { '/' });
                    CSTDate = RegInterState[1].ToString() + "/" + RegInterState[0].ToString() + "/" + RegInterState[2].ToString();
                }
                if (txtRegTaxDeductionDate.Text != "")
                {
                    string[] RegTaxDeduction = txtRegTaxDeductionDate.Text.Split(new char[] { '/' });
                    TDSDate = RegTaxDeduction[1].ToString() + "/" + RegTaxDeduction[0].ToString() + "/" + RegTaxDeduction[2].ToString();
                }
                if (txtRegServiceTaxDate.Text != "")
                {
                    string[] RegService = txtRegServiceTaxDate.Text.Split(new char[] { '/' });
                    STDate = RegService[1].ToString() + "/" + RegService[0].ToString() + "/" + RegService[2].ToString();
                }
                if (txtRegLuxuryDate.Text != "")
                {
                    string[] RegLuxury = txtRegLuxuryDate.Text.Split(new char[] { '/' });
                    LTDate = RegLuxury[1].ToString() + "/" + RegLuxury[0].ToString() + "/" + RegLuxury[2].ToString();
                }
                if (txtRegCVNNETDate.Text != "")
                {
                    string[] RegCVNNET = txtRegCVNNETDate.Text.Split(new char[] { '/' });
                    CENVATDate = RegCVNNET[1].ToString() + "/" + RegCVNNET[0].ToString() + "/" + RegCVNNET[2].ToString();
                }

                SqlParameter[] sparam = 
                                        {
                                            new SqlParameter("@LID",LID),
                                            //new SqlParameter("@REGID",DT.Rows[0]["REGID"].ToString()),
                                            new SqlParameter("@PAN",txtRegPAN.Text.Trim()),
                                            new SqlParameter("@PANDATE",PANDate),
                                            new SqlParameter("@VATTIN",txtRegVAT.Text.Trim()),
                                            new SqlParameter("@VATTINDATE",VatDate.ToString()),
                                            new SqlParameter("@CSTNO",txtRegInterState.Text.Trim()),
                                            new SqlParameter("@CSTDATE",CSTDate.ToString()),
                                            new SqlParameter("@TDSNO",txtRegTaxDeduction.Text.Trim()),
                                            new SqlParameter("@TDSDATE",TDSDate.ToString()),
                                            new SqlParameter("@SERTNO",txtRegServicetax.Text.Trim()),
                                            new SqlParameter("@SERTNDATE",STDate.ToString()),
                                            new SqlParameter("@LTNO",txtRegLuxury.Text.Trim()),
                                            new SqlParameter("@LTNDATE",LTDate.ToString()),
                                            new SqlParameter("@CEPAN",txtRegCVNNET.Text.Trim()),
                                            new SqlParameter("@CEPANDATE",CENVATDate.ToString()),
                                            new SqlParameter("@PANREF",txtRegPanRef.Text.Trim()),
                                            new SqlParameter("@ENAME",Session["username"].ToString())                                            
                                        };
                du.executeprocedure("USP_Update_ACC_SaveRegistrationDetails", sparam);

            }
            else
            {
                lblMsg.Text = "insert";
                string PANDate = "";
                string VatDate = "";
                string CSTDate = "";
                string TDSDate = "";
                string STDate = "";
                string LTDate = "";
                string CENVATDate = "";
                if (txtRegPANDate.Text != "")
                {
                    string[] Pan = txtRegPANDate.Text.Split(new char[] { '/' });
                    PANDate = Pan[1].ToString() + "/" + Pan[0].ToString() + "/" + Pan[2].ToString();
                }
                if (txtRegVATDate.Text != "")
                {
                    string[] DedcutionTax = txtRegVATDate.Text.Split(new char[] { '/' });
                    VatDate = DedcutionTax[1].ToString() + "/" + DedcutionTax[0].ToString() + "/" + DedcutionTax[2].ToString();
                }
                if (txtRegInterStateDate.Text != "")
                {
                    string[] RegInterState = txtRegInterStateDate.Text.Split(new char[] { '/' });
                    CSTDate = RegInterState[1].ToString() + "/" + RegInterState[0].ToString() + "/" + RegInterState[2].ToString();
                }
                if (txtRegTaxDeductionDate.Text != "")
                {
                    string[] RegTaxDeduction = txtRegTaxDeductionDate.Text.Split(new char[] { '/' });
                    TDSDate = RegTaxDeduction[1].ToString() + "/" + RegTaxDeduction[0].ToString() + "/" + RegTaxDeduction[2].ToString();
                }
                if (txtRegServiceTaxDate.Text != "")
                {
                    string[] RegService = txtRegServiceTaxDate.Text.Split(new char[] { '/' });
                    STDate = RegService[1].ToString() + "/" + RegService[0].ToString() + "/" + RegService[2].ToString();
                }
                if (txtRegLuxuryDate.Text != "")
                {
                    string[] RegLuxury = txtRegLuxuryDate.Text.Split(new char[] { '/' });
                    LTDate = RegLuxury[1].ToString() + "/" + RegLuxury[0].ToString() + "/" + RegLuxury[2].ToString();
                }
                if (txtRegCVNNETDate.Text != "")
                {
                    string[] RegCVNNET = txtRegCVNNETDate.Text.Split(new char[] { '/' });
                    CENVATDate = RegCVNNET[1].ToString() + "/" + RegCVNNET[0].ToString() + "/" + RegCVNNET[2].ToString();
                }

                SqlParameter[] sparam = 
                                        {
                                            new SqlParameter("@LID",LID),
                                            new SqlParameter("@REGID","0"),
                                            new SqlParameter("@PAN",txtRegPAN.Text.Trim()),
                                            new SqlParameter("@PANDATE",PANDate.ToString()),
                                            new SqlParameter("@VATTIN",txtRegVAT.Text.Trim()),
                                            new SqlParameter("@VATTINDATE",VatDate.ToString()),
                                            new SqlParameter("@CSTNO",txtRegInterState.Text.Trim()),
                                            new SqlParameter("@CSTDATE",CSTDate.ToString()),
                                            new SqlParameter("@TDSNO",txtRegTaxDeduction.Text.Trim()),
                                            new SqlParameter("@TDSDATE",TDSDate.ToString()),
                                            new SqlParameter("@SERTNO",txtRegServicetax.Text.Trim()),
                                            new SqlParameter("@SERTNDATE",STDate.ToString()),
                                            new SqlParameter("@LTNO",txtRegLuxury.Text.Trim()),
                                            new SqlParameter("@LTNDATE",LTDate.ToString()),
                                            new SqlParameter("@CEPAN",txtRegCVNNET.Text.Trim()),
                                            new SqlParameter("@CEPANDATE",CENVATDate.ToString()),
                                            new SqlParameter("@PANREF",txtRegPanRef.Text.Trim()),
                                            new SqlParameter("@CNAME",Session["username"].ToString())
                                        };

                du.executeprocedure("USP_ACC_SaveRegistrationDetails", sparam);
            }
        }
        catch (Exception ex)
        {
            lblMsg.Attributes.Remove("class");
            lblMsg.Attributes.Add("class", "false");
            lblMsg.Text = ex.Message;
        }
    }
    protected void UpdateOthersDetails()
    {
        try
        {
            string sql1 = "select * from  ACC_LEDOTHERDETAILS where lid=" + LID;
            DataTable DT = du.getdata(sql1);
            if (DT.Rows.Count > 0)
            {
                //lblMsg.Text="updateotherdetails";

                SqlParameter[] sparam = 
                                        { 
                                            new SqlParameter("@LID",LID),
                                            new SqlParameter("@ACTIVE",CHKAvtive.Checked),
                                            new SqlParameter("@TCS",chkApplyTCS.Checked),
                                            new SqlParameter("@CREDITPERIOD",txtCreditPeriod.Text.Trim()),
                                            new SqlParameter("@CREDITLIMIT",txtCreditLimit.Text.Trim()),
                                            new SqlParameter("@PURTAXMAINCLASSID",ddlPurchase.SelectedValue),
                                            new SqlParameter("@SALETAXMAINCLASSID",ddlSales.SelectedValue),
                                            new SqlParameter("@SPRID",ddlSalePerson.SelectedValue),
                                            new SqlParameter("@SPGID",ddlPriceGroup.SelectedValue),
                                            new SqlParameter("@SUBTAXID","0"),
                                            new SqlParameter("@ENAME",Session["username"].ToString())
                                        };
                du.executeprocedure("USP_Update_ACC_SaveLedgerOtherDetails", sparam);

            }
            else
            {

                SqlParameter[] sparam = 
                                        { 
                                            new SqlParameter("@LID",LID),
                                            new SqlParameter("@ACTIVE",CHKAvtive.Checked),
                                            new SqlParameter("@TCS",chkApplyTCS.Checked),
                                            new SqlParameter("@CREDITPERIOD",txtCreditPeriod.Text.Trim()),
                                            new SqlParameter("@CREDITLIMIT",txtCreditLimit.Text.Trim()),
                                            new SqlParameter("@PURTAXMAINCLASSID",ddlPurchase.SelectedValue),
                                            new SqlParameter("@SALETAXMAINCLASSID",ddlSales.SelectedValue),
                                            new SqlParameter("@SPRID",ddlSalePerson.SelectedValue),
                                            new SqlParameter("@SPGID",ddlPriceGroup.SelectedValue),
                                            new SqlParameter("@SUBTAXID","0"),
                                            new SqlParameter("@CNAME",Session["username"].ToString())
                                        };
                du.executeprocedure("USP_ACC_SaveLedgerOtherDetails", sparam);
            }
        }
        catch (Exception ex)
        {
            lblMsg.Attributes.Remove("class");
            lblMsg.Attributes.Add("class", "false");
            lblMsg.Text = ex.Message;
        }
    }
    protected void UpdateTermConditions()
    {

        try
        {
            string sql1 = "select TRMID from  ACC_LEDTERMSCONDITIONS where lid=" + LID;
            DataTable DT = du.getdata(sql1);
            if (DT.Rows.Count > 0)
            {

                SqlParameter[] sparam =
                                        {
                                            new SqlParameter("@LID",LID),
                                            new SqlParameter("@TRMID",lstTermCondition.SelectedValue),
                                            new SqlParameter("@ENAME",Session["username"].ToString())
                                        };
                du.executeprocedure("usp_Update_ACC_LEDTERMSCONDITIONS", sparam);
            }
            else
            {
                SqlParameter[] sparam =
                                        {
                                            new SqlParameter("@LID",LID),
                                            new SqlParameter("@TRMID",lstTermCondition.SelectedValue),
                                            new SqlParameter("@CNAME",Session["username"].ToString())
                                        };
                du.executeprocedure("usp_insert_ACC_LEDTERMSCONDITIONS", sparam);
            }
        }
        catch (Exception ex)
        {
            lblMsg.Attributes.Remove("class");
            lblMsg.Attributes.Add("class", "false");
            lblMsg.Text = ex.Message;
        }
    }
    private void EmptyTextBoxes(Control parent)
    {
        // Loop through all the controls on the page
        foreach (Control c in parent.Controls)
        {
            // Check and see if it's a textbox
            if ((c.GetType() == typeof(TextBox)))
            {
                // Since its a textbox clear out the text  
                ((TextBox)(c)).Text = "";
            }
            if ((c.GetType() == typeof(DropDownList)))
            {
                // Since its a textbox clear out the text  
                ((DropDownList)(c)).SelectedValue = "0";
            }
            // Now we need to call itself (recursive) because
            // all items (Panel, GroupBox, etc) is a container
            // so we need to check all containers for any
            // textboxes so we can clear them
            if (c.HasControls())
            {
                EmptyTextBoxes(c);
            }
        }
    }
    protected void BtnUpdate_Click(object sender, EventArgs e)
    {
        if (ValidateLedger1() && ValidateLedger())
        {
            UpdateWithGroup();
            UpdateTaxDetails();
            UpdateAddressDetails();
            UpdateDeliveryDetails();
            UpdateRegistrationDetails();
            UpdatetContactDetails();
            UpdateOthersDetails();
            UpdateTermConditions();

            lblMsg.Attributes.Remove("class");
            lblMsg.Attributes.Add("class", "true");
            lblMsg.Text = "Customer Detail Updated Successfully";
        }
    }
    protected void BtnClose_Click(object sender, EventArgs e)
    {
        Response.Redirect("Customer.aspx?action=view");
    }
    protected void chk_CheckedChanged(object sender, EventArgs e)
    {
        //if (chk.Checked == true)
        //{
        //    string name = txtAddName.Text.ToString();
        //    string ddlname = ddlName.SelectedItem.Text;
        //    string add1 = txtAddress1.Text.ToString();
        //    string add2 = txtAddress2.Text.ToString();
        //    string add3 = txtAddress3.Text.ToString();
        //    string place = txtAddPlace.Text.ToString();
        //    string pin = Convert.ToString(txtPin.Text.ToString());
        //    string state = ddlState.SelectedItem.Text;
        //    string country = ddlCountry.SelectedItem.Text;
        //    txtDileveryName.Text = name;
        //    DDLDileveryName.SelectedItem.Text = ddlname;
        //    txtDileveryAddress1.Text = add1;
        //    txtDileveryAddress2.Text = add2;
        //    txtDileveryAddress3.Text = add3;
        //    DDLDileveryPlace.Text = place;
        //    txtDileveryPincode.Text = pin;
        //    DDLDileveryState.SelectedItem.Text = state;
        //    DDLDileveryCountry.SelectedItem.Text = country;
        //}
        //else if (chk.Checked == false)
        //{
        //    txtDileveryName.Text = "";
        //    DDLDileveryName.SelectedItem.Text = "";
        //    txtDileveryAddress1.Text = "";
        //    txtDileveryAddress2.Text = "";
        //    txtDileveryAddress3.Text = "";
        //    DDLDileveryPlace.Text = "";
        //    txtDileveryPincode.Text = "";
        //    DDLDileveryState.SelectedItem.Text = "";
        //    DDLDileveryCountry.SelectedItem.Text = "";
        //}
    }
}
